package com.lgkj.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lgkj.R;
import com.lgkj.bean.MovieTypeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/21 0021.
 */

public class MovieTypeAdapter extends RecyclerView.Adapter<MovieHolder> {
    private Context context;
    private List<MovieTypeBean.DataBean> dataBeans;
    private View.OnClickListener mItemClickListener;
    public MovieTypeAdapter(Context context) {
        this.context = context;
        dataBeans = new ArrayList<>();
    }
    public void setItemClickListener(View.OnClickListener itemClickListener) {
        mItemClickListener = itemClickListener;
    }
    public void setdata(List<MovieTypeBean.DataBean> dataBean) {
        this.dataBeans = dataBean;
    }

    @NonNull
    @Override
    public MovieHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_news, null);
        MovieHolder myViewHolder = new MovieHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MovieHolder holder, int position) {
        holder.iv_name.setTag(position);
        holder.iv_name.setOnClickListener(mItemClickListener);
        holder.iv_name.setText(dataBeans.get(position).getType().getVideo_type_name());
    }


    @Override
    public int getItemCount() {
        return dataBeans.size();
    }

    public MovieTypeBean.DataBean getItem(int position){
       return dataBeans.get(position);
    }
}

class MovieHolder extends RecyclerView.ViewHolder {
    TextView iv_name;

    public MovieHolder(View itemView) {
        super(itemView);
        iv_name = itemView.findViewById(R.id.tv_name);
    }

}

